package biolean;

import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;

import org.junit.Test;

import biolean.commands.CmdRegister;
import biolean.commands.Command;
import biolean.commands.Filter;
import biolean.commands.SubstractCmd;
import biolean.files.AnnotationFile;
import biolean.files.BioFile;
import biolean.files.SequenceFile;
import biolean.logic.Connection;
import biolean.logic.Pair;
import biolean.logic.Project;

public class Tests
{

	@Test
	public void test()
	{
		//fail("Not yet implemented");
		
		ArrayList<Connection> connections = new ArrayList<Connection>();
		Project graf = new Project(connections, null);
		BioFile outSequence = new SequenceFile();
		BioFile inAnnotation = new AnnotationFile();
		BioFile inAnnotation2 = new AnnotationFile();
		BioFile inAnnotation3 = new SequenceFile("ob3");
		BioFile ob4 = new SequenceFile("ob4");
		
		List<Pair<String, BioFile> > list = new ArrayList<Pair<String,BioFile>>();	
		Pair<String, BioFile> p1 = new Pair<String, BioFile>("jedna", outSequence);
		Pair<String, BioFile> p2 = new Pair<String, BioFile>("dva", inAnnotation);
		Pair<String, BioFile> p3 = new Pair<String, BioFile>("tri", inAnnotation3);
		
		list.add(p1);
		list.add(p2);
		list.add(p3);
		
		Pair<String, BioFile> ep1 = new Pair<String, BioFile>("jedna", outSequence);
		Pair<String, BioFile> ep2 = new Pair<String, BioFile>("dva", inAnnotation);
		Pair<String, BioFile> ep3 = new Pair<String, BioFile>("tri", inAnnotation3);
		
		Pair<String, BioFile> badp1 = new Pair<String, BioFile>("jeda", outSequence);
		Pair<String, BioFile> badp2 = new Pair<String, BioFile>("da", inAnnotation);
		Pair<String, BioFile> badp3 = new Pair<String, BioFile>("ti", inAnnotation3);
		
		
		Assert.assertTrue( list.contains( p1 ) );
		Assert.assertTrue( list.contains( p2 ) );
		Assert.assertTrue( list.contains( p3 ) );
		
		Assert.assertTrue( list.contains( ep1 ) );
		Assert.assertTrue( list.contains( ep2 ) );
		Assert.assertTrue( list.contains( ep3 ) );
		
		Assert.assertFalse( list.contains( badp1 ) );
		Assert.assertFalse( list.contains( badp3 ) );
		Assert.assertFalse( list.contains( badp2 ) );
		//testy grafu
		

		
		Command cmd = new SubstractCmd();
		
		Assert.assertTrue( graf.connect(cmd, outSequence) );
		Assert.assertFalse( graf.connect(cmd, outSequence) );
		Assert.assertFalse( graf.connect(outSequence , cmd) );
		Assert.assertTrue( graf.connect(inAnnotation , cmd) );
		
		Assert.assertFalse( graf.connect(inAnnotation2, cmd) );
		Assert.assertFalse ( graf.connect( cmd , inAnnotation3));
		Assert.assertTrue ( graf.connect(inAnnotation3, cmd));
		Assert.assertFalse ( graf.connect(inAnnotation3, cmd));
		
		Assert.assertFalse( graf.disconnect(cmd, inAnnotation3) );
		Assert.assertTrue( graf.disconnect( inAnnotation3, cmd) );
		
		Assert.assertFalse ( graf.connect( cmd , inAnnotation3));
		Assert.assertTrue ( graf.connect(inAnnotation3, cmd));
		
		Assert.assertFalse( graf.disconnect(cmd, ob4));
		Assert.assertFalse( graf.disconnect(ob4, cmd));
		
		Assert.assertFalse( graf.connect(cmd, ob4));
		Assert.assertFalse( graf.connect(ob4, cmd));
		
		Assert.assertTrue( graf.disconnect(cmd , outSequence ) );
		Assert.assertFalse( graf.connect(cmd , inAnnotation ) );
		Assert.assertTrue( graf.connect(cmd , outSequence ) );
		
		Command cmd2 = new SubstractCmd();
		
		Assert.assertTrue( graf.connect(outSequence , cmd2 ) );
		
		Assert.assertFalse( graf.connect(outSequence , cmd2 ) );
		
		Assert.assertFalse( graf.connect( cmd2, outSequence ) );
		
		Assert.assertTrue( graf.connect(inAnnotation2, cmd2) );
		
		BioFile outSequence2 = new SequenceFile("path"  );
				
		Assert.assertTrue( graf.connect(cmd2, outSequence2) );
		
		CmdRegister register = new CmdRegister();
		register.register("filter", Filter.class);
		register.register("substract", SubstractCmd.class);
		Assert.assertEquals("filter",  register.findCommandName(Filter.class)) ;
		Assert.assertEquals("substract",  register.findCommandName(SubstractCmd.class)) ;
		Assert.assertEquals(null,  register.findCommandName(Command.class)) ;
		Assert.assertEquals(SubstractCmd.class,  register.findClass("substract")) ;
		Assert.assertEquals(Filter.class,  register.findClass("filter")) ;
		Assert.assertNotSame(Filter.class,  register.findClass("substract")) ;
	}
}
